package com.yint.http.bodys;

import java.io.IOException;
import java.io.OutputStream;

import com.yint.http.api.Body;

public abstract class AbsBody implements Body
{

	@Override
	public final void toStream( OutputStream os ) throws IOException
	{
		if ( os != null )
		{
			byte[] bytes = toBytes();
			if ( bytes != null && bytes.length > 0 )
			{
				os.write( bytes );
				os.flush();
			}
		}
	}

	@Override
	public final String toStr() throws IOException
	{
		return getStrContent();
	}

	@Override
	public final byte[] toBytes() throws IOException
	{
		return getByteContent();
	}

	protected abstract String getStrContent();

	protected abstract byte[] getByteContent();

	@Override
	public String getHost()
	{
		return null;
	}

	@Override
	public int getPort()
	{
		return -1;
	}

	@Override
	public String getScheme()
	{
		return null;
	}

	@Override
	public String getUrl()
	{
		return null;
	}
}
